package cmd

import (
	"oc_contributor_chenliangzhu/pkg/logging"

	"github.com/spf13/cobra"
)

var Verbose bool

var RootCmd = CreateRootCmd()

func CreateRootCmd() *cobra.Command {
	var rootCmd = &cobra.Command{
		Use:   "gopack",
		Short: "Go应用容器化构建工具",
		Long:  `gopack是一个针对OpenCloudOS9平台的Go应用容器化构建工具，支持CGO，提供依赖分析和安全扫描功能。`,
		SilenceErrors: true,
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
			logging.Setup(Verbose)
		},
		// 当没有提供子命令时显示帮助信息
		Run: func(cmd *cobra.Command, args []string) {
			cmd.Help()
		},
	}
	rootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
	rootCmd.AddCommand(VersionCmd)
	rootCmd.AddCommand(BuildCmd)
	rootCmd.AddCommand(ScanCmd)
	rootCmd.AddCommand(DocsCmd)
	return rootCmd
}